#include "shipDesign.h"
#include "shipChooser.h"
#include "luaResources.h"
#include <QDebug>

ShipDesign::ShipDesign()
{
  mUI.setupUi(this);

  LuaResources& lua(LuaResources::getLuaResources());
  mUI.itemTable->addComponents(lua.components, lua.graphics);

  connect(mUI.newButton, SIGNAL(clicked()),
          this, SLOT(onNewShip()));
  connect(mUI.loadButton, SIGNAL(clicked()),
          this, SLOT(onLoadShip()));
  connect(mUI.saveButton, SIGNAL(clicked()),
          this, SLOT(onSaveShip()));
  connect(mUI.cancelButton, SIGNAL(clicked()),
          this, SLOT(onCancel()));
  connect(mUI.continueButton, SIGNAL(clicked()),
          this, SLOT(onContinue()));
}

void ShipDesign::onNewShip()
{
  qDebug() << "onNewShip";
  mUI.shipDisplay->clear();
}

void ShipDesign::onLoadShip()
{
  qDebug() << "onLoadShip";
  ShipChooser sc;
  if (sc.exec())
  {
    mUI.name->setText(sc.ship());
    ShipInventory inventory(sc.ship());
    mUI.shipDisplay->loadShip(inventory);
  }
}

void ShipDesign::onSaveShip()
{
  qDebug() << "onSaveShip";
  ShipInventory inventory(mUI.shipDisplay->shipInventory());
  inventory.setName(mUI.name->text());
  inventory.save();
}

void ShipDesign::onCancel()
{
  qDebug() << "onCancel";
}

void ShipDesign::onContinue()
{
  qDebug() << "onContinue";
}
